﻿using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Http.HttpResults;
using Microsoft.AspNetCore.Mvc;
using System.CJL.API.Application.Command.ProcessCommand;
using System.CJL.API.DTO;
using System.CJL.Domain;
using System.CJL.Domain.DTO;
using static Share.ParseAPI;

namespace System.CJL.API.Controllers
{
    /// <summary>
    /// 工序控制器
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class ProcessController : ControllerBase
    {
        IMediator _mediator;
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="mediator"></param>
        public ProcessController(IMediator mediator)
        {
            _mediator=mediator;
        }
        /// <summary>
        /// 工序显示
        /// </summary>
        /// <param name="t"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<ApiResult<PageDTO<Process>>> ProcessShow([FromQuery]ProcessShowCommand t)
        {
            ApiResult<PageDTO<Process>> result = new ApiResult<PageDTO<Process>>();
            try
            {
                result.Data = await _mediator.Send(t);
            }
            catch (Exception ex)
            {
                result.Message = ex.Message;
                result.Code = -1;
                throw;
            }
            return result;
        }
        /// <summary>
        /// 工序添加
        /// </summary>
        /// <param name="t"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ApiResult<int>> ProcessAdd(ProcessAddCommand t)
        {
            ApiResult<int> result = new ApiResult<int>();
            try
            {
                result.Data = await _mediator.Send(t);
            }
            catch (Exception ex)
            {
                result.Message = ex.Message;
                result.Code = -1;
                throw;
            }
            return result;
        }
        /// <summary>
        /// 工序修改
        /// </summary>
        /// <param name="t"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ApiResult<int>> ProcessUpdate(ProcessUpdateCommand t)
        {
            ApiResult<int> result = new ApiResult<int>();
            try
            {
                result.Data = await _mediator.Send(t);
            }
            catch (Exception ex)
            {
                result.Message = ex.Message;
                result.Code = -1;
                throw;
            }
            return result;
        }
        /// <summary>
        /// 工序返填
        /// </summary>
        /// <param name="t"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<ApiResult<Process>> ProcessMondel([FromQuery]ProcessMondelCommand t)
        {
            ApiResult<Process> result = new ApiResult<Process>();
            try
            {
                result.Data = await _mediator.Send(t);
            }
            catch (Exception ex)
            {
                result.Message = ex.Message;
                result.Code = -1;
                throw;
            }
            return result;
        }
		/// <summary>
		/// 工序删除
		/// </summary>
		/// <param name="t"></param>
		/// <returns></returns>
		[HttpPost]
		public async Task<ApiResult<int>> ProcessDelete(ProcessDeleteCommand t)
		{
            ApiResult<int> result = new ApiResult<int>();
            try
            {
                result.Data = await _mediator.Send(t);
            }
            catch (Exception ex)
            {
                result.Message = ex.Message;
                result.Code = -1;
                throw;
            }
            return result;
        }
		/// <summary>
		/// 工序批量删除
		/// </summary>
		/// <param name="t"></param>
		/// <returns></returns>
		[HttpPost]
		public async Task<ApiResult<int>> ProcessDeletepi(ProcessDeletePiCommand t)
		{
            ApiResult<int> result = new ApiResult<int>();
            try
            {
                result.Data = await _mediator.Send(t);
            }
            catch (Exception ex)
            {
                result.Message = ex.Message;
                result.Code = -1;
                throw;
            }
            return result;
        }
	}
}
